package cn.iocoder.yudao.module.scrm.controller.admin.marketing;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.scrm.controller.admin.marketing.vo.operation.*;
import cn.iocoder.yudao.module.scrm.service.marketing.operation.MarketingOperationService;
import cn.iocoder.yudao.module.system.api.social.SocialClientApi;
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * @Author LiZhiMin
 * @Date 2024/8/9 14:53
 */
@Tag(name = "管理后台 - 营销操作控制")
@RestController
@RequestMapping("/scrm/marketing-operation")
@Validated
public class MarketingOperationController {

    @Resource
    private MarketingOperationService marketingOperationService;



    //TODO 1.访客进行转发操作
    @PostMapping("/transmit")
    @Operation(summary = "员工|访客-转发营销内容-进行记录转发次数和数据")
    public CommonResult<TransmitRespVO> transmit(@Valid @RequestBody TransmitReqVO vo) {
        return success(marketingOperationService.transmit(vo));
    }

    //TODO 2.员工进行访问操作
    @PostMapping("/visitor")
    @Operation(summary = "员工|访客-访问营销内容进行记录浏览数据")
    @PermitAll
    public CommonResult<VisitorRespVO> visitor(@RequestHeader("Tenant-Id") Integer tenantId,@Valid @RequestBody VisitorReqVO vo) {
        return success(marketingOperationService.visitor(tenantId,vo));
    }


    @PostMapping("/sendMessage")
    @Operation(summary = "发送访问雷达信息 转发|开始浏览|完成浏览")
    @PermitAll
    //@PreAuthorize("@ss.hasPermission('scrm:marketing-content:create')")
    public CommonResult<Boolean> sendMessage(@RequestHeader("Tenant-Id") Integer tenantId, @Valid @RequestBody SendMessageVo vo) {
        return success(marketingOperationService.sendMessage(tenantId,vo));
    }


    @PostMapping("/getWeChatInfoByCode")
    @Operation(summary = "用户授权后获取微信用户的信息根据code")
        public CommonResult<WxInfoRespVo> getWeChatInfoByCode(@RequestHeader("Tenant-Id") Integer tenantId, @Valid @RequestBody WxAuthorizerReqVo vo) {
        return success(marketingOperationService.getWeChatInfoByCode(tenantId,vo));
    }


    //需要在system_social_client表中添加微信小程序的记录信息  socialType为34 userType为1
    @GetMapping(  "/getWxPhone")
    @Operation(summary = "获得微信小程序的手机信息-调用rpc方法")
    @PermitAll
    @Parameters({
            @Parameter(name = "userType", description = "用户类型", example = "1", required = true),
            @Parameter(name = "phoneCode", description = "手机授权码", example = "yudao11", required = true)
    })
    CommonResult<SocialWxPhoneNumberInfoRespDTO> getWxPhone(@RequestParam("userType") Integer userType,
                                                                        @RequestParam("phoneCode") String phoneCode){
        return success(marketingOperationService.getWxPhone(userType,phoneCode));

    }
    //TODO 3. 访客通过手机号码进行授权访问








}
